package patrones;

import java.sql.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
// patron de template

public abstract class plantilla_conectar {;
protected String usuario;
protected String clave;
protected ResultSet rs;
protected Connection con;
protected Statement stmt;
protected String driver;
protected String conneccion;

public abstract boolean abrir_conectar();
public abstract boolean cerrar_conectar();


public final void consultarSQL(String consulta) {
	abrir_conectar();
	try {
		Class.forName(driver);
		con = DriverManager.getConnection(conneccion, usuario, clave);
		stmt = con.createStatement();
		rs = stmt.executeQuery(consulta);
	} catch (Exception e) {
		System.out.println(e.getMessage());
	}
}

public final int autogenerar(String consulta) {
	abrir_conectar();
	int codigo = 1;
	try {
		Class.forName(driver);
		con = DriverManager.getConnection(conneccion, usuario, clave);
		stmt = con.createStatement();
		rs = stmt.executeQuery(consulta);
		while (rs.next()) {
			codigo = rs.getInt(1) + 1;
		}
	} catch (Exception e) {
		System.out.println(e.getMessage());
	}
	return codigo;
}


}
